package realQuestion.kedaXunfei;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main2 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        String nowTime = scanner.next();
        int times = scanner.nextInt();
        ArrayList<String> dates = new ArrayList<>();
        for (int i = 0; i < times; i++) {
            dates.add(scanner.next());
        }

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < 5; i++) {
            if (i!=2){
                sb.append(nowTime.charAt(i));
            }
        }
        int now=Integer.parseInt(sb.toString());



        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < times; i++) {
            StringBuffer sb1 = new StringBuffer();
            String s = dates.get(i);
            for (int j= 0; j < 5; j++) {
                if (j!=2){
                    sb1.append(s.charAt(j));
                }
            }
            list.add(Integer.parseInt(sb1.toString()));
        }


        int[] nums = new int[times];
        for (int i = 0; i < times; i++) {
            nums[i]=list.get(i);
        }
        Arrays.sort(nums);


        int nextTime=0;
        for (int i = 0; i < times; i++) {
            if (nums[i]>now){
                nextTime=nums[i];
                break;
            }
        }
        String next="";
        if (nextTime>=1000){
            String s=nextTime+"";
             next=s.substring(0,2)+":"+s.substring(2,4);
        }else  if (nextTime>100&&nextTime<1000){
            String s=nextTime+"";
            next="0"+s.charAt(0)+":"+s.substring(1,3);
        }else {
            next="00:"+nextTime;

        }



        System.out.println(next);



    }


}
